package com.diaohaiwen.framework.file;


import io.minio.MinioClient;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author 刁海文
 * @since 2023/6/15 21:53
 * @Remark
 */
@Configuration
@ConfigurationProperties(prefix = "minio")
public class FileConfig {
    /**
     * 文件服务器地址
     */
    private String url;

    /**
     * 登录用户名
     */
    private String accessKey;

    /**
     * 登录密码
     */
    private String secretKey;

    @Bean
    public MinioClient getMinioClient() {
        MinioClient client = MinioClient.builder()
                .credentials(accessKey, secretKey)
                .endpoint(url).build();
        MinioUtil.client = client;
        return client;
    }

    public FileConfig setUrl(String url) {
        this.url = url;
        return this;
    }

    public void setAccessKey(String accessKey) {
        this.accessKey = accessKey;
    }

    public void setSecretKey(String secretKey) {
        this.secretKey = secretKey;
    }


    public String fileUrl(String bucket, String file) {
        return url + "/" + bucket + "/" + file;
    }

}
